/**
	Ludibrium PQ (101st Eos Tower)
*/

function init() {
    em.setProperty("started", "false");
}

function monsterValue(eim, mobId) {
    return 1;
}

function setup() {
    em.setProperty("started", "true");

    var eim = em.newInstance("LudiPQ");

    var mf = em.getMapFactory(em.getWorld());
    
    var map = mf.getMap(922010100);
    map.killAllMonsters(false);
    map.respawn(true);

    mf.getMap(922010200).resetReactors();
    mf.getMap(922010201).resetReactors();
    mf.getMap(922010300).resetReactors();

    map = mf.getMap(922010401);
    map.killAllMonsters(false);
    map.respawn(true);

    map = mf.getMap(922010402);
    map.killAllMonsters(false);
    map.respawn(true);

    map = mf.getMap(922010403);
    map.killAllMonsters(false);
    map.respawn(true);

    map = mf.getMap(922010404);
    map.killAllMonsters(false);
    map.respawn(true);

    map = mf.getMap(922010405);
    map.killAllMonsters(false);
    map.respawn(true);

    map = mf.getMap(922010500);
    map.killAllMonsters(false);
    map.respawn(true);
    
    mf.getMap(922010501).resetReactors();
    mf.getMap(922010502).resetReactors();
    mf.getMap(922010503).resetReactors();
    mf.getMap(922010504).resetReactors();
    mf.getMap(922010505).resetReactors();

    map = mf.getMap(922010506);
    map.killAllMonsters(false);
    map.respawn(true);
    map.resetReactors();

    map = mf.getMap(922010700);
    map.killAllMonsters(false);
    map.respawn(true);
    map.resetReactors();

    map = mf.getMap(922010900);
    map.killAllMonsters(false);
    map.respawn(true);
    map.resetReactors();

    mf.getMap(922011000).resetReactors();

    eim.startEventTimer(60 * 1000 * 60);

    return eim;
}

function scheduledTimeout(eim) {
    eim.disposeIfPlayerBelow(100, 922010000);

    em.setProperty("started", "false");
}

function changedMap(eim, player, mapid) {
    switch (mapid) {
	case 922010100: // Stage 1
	case 922010200: // Stage 2
	case 922010201: // Stage 2 - Tower's Trap'
	case 922010300: // Stage 3
	case 922010400: //stage 4
	case 922010401: //darkness in stage 4
	case 922010402: //darkness in stage 4
	case 922010403: //darkness in stage 4
	case 922010404: //darkness in stage 4
	case 922010405: //darkness in stage 4
	case 922010500: //stage 5
	case 922010501: //tower's maze in stage 5
	case 922010502: //tower's maze in stage 5
	case 922010503: //tower's maze in stage 5
	case 922010504: //tower's maze in stage 5
	case 922010505: //tower's maze in stage 5
	case 922010506: //tower's maze in stage 5
	case 922010600:
	case 922010700: //stage 7
	case 922010800:
	case 922010900: //crack on the wall
	case 922011000: //bonus
	    return;
    }
    eim.unregisterPlayer(player);

    if (eim.disposeIfPlayerBelow(0, 0)) {
	em.setProperty("started", "false");
    }
}

function playerEntry(eim, player) {
    var map = em.getMapFactory(em.getWorld()).getMap(922010100);
    player.changeMap(map, map.getPortal(0));
}

function playerRevive(eim, player) {
}

function playerDisconnected(eim, player) {
    return -3;
}

function leftParty(eim, player) {			
    // If only 2 players are left, uncompletable
    if (eim.disposeIfPlayerBelow(minPlayers, 922010000)) {
	em.setProperty("started", "false");
    } else {
	playerExit(eim, player);
    }
}

function disbandParty(eim) {
    // Boot whole party and end
    eim.disposeIfPlayerBelow(100, 922010000);

    em.setProperty("started", "false");
}

function playerExit(eim, player) {
    var map = em.getMapFactory(em.getWorld()).getMap(922010000);

    eim.unregisterPlayer(player);
    player.changeMap(map, map.getPortal(0));
}

// For offline players
function removePlayer(eim, player) {
    eim.unregisterPlayer(player);
}

function clearPQ(eim) {
    eim.disposeIfPlayerBelow(100, 922010000);

    em.setProperty("started", "false");
}

function finish(eim) {
    eim.disposeIfPlayerBelow(100, 0);

    em.setProperty("started", "false");
}

function timeOut(eim) {
    eim.disposeIfPlayerBelow(100, 922010000);

    em.setProperty("started", "false");
}

function cancelSchedule() {}
function playerDead() {}
function allMonstersDead(eim) {}